
// https://leetcode.cn/problems/remove-linked-list-elements/submissions/
public class RemoveElement {
    private static class  ListNode{
        int val;
        ListNode next;
        public ListNode(){}

    }

    class Solution {
        public ListNode removeElements(ListNode head, int val) {
            ListNode dummy = new ListNode();
            dummy.next = head;
            ListNode pre = dummy;
            ListNode cur = head;
            while(cur != null){
                if(cur.val == val){
                    ListNode next = cur.next;
                    pre.next = next;
                    cur = next;
                }else{
                    pre = cur;
                    cur = cur.next;
                }

            }
            return dummy.next;

        }
    }
}
